<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta charset="utf-8">
    <title>诊疗信息管理界面</title>
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">
  </head>
  
    <script src="<%=path%>/plugins/layui/layui.js"></script>

<body>
	<!-- 搜索模块 -->
	<div class="demoTable" style="margin-top:7px;margin-left:50px">
	  <div class="layui-inline layui-icon layui-icon layui-icon-search" 
	     style="font-size: 20px; color: #2B2B2B;font-weight:bold">模糊搜索：
	  </div>
	  
	  <div class="layui-inline">
	    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
	  </div>
	  
	  <span class="layui-badge-dot"></span>
	  
      <div class="layui-inline layui-icon layui-icon layui-icon-release" 
	     style="font-size: 20px; color: #2B2B2B;font-weight:bold"> 时间段查询：
	  </div>
	  
      <div class="layui-input-inline">
        <input type="text" class="layui-input" style="width: 330px" id="time" placeholder="  开始 到 结束 ">
      </div>
      
	  <button class="layui-btn" data-type="reload">搜索</button>

	</div>
	<!-- 表格体 lay-filter相当于id -->
	<table id="stuTable" lay-filter="tableDemo"></table>

</body>

<script>
	//调用模块
	layui.use(['table','jquery','laydate','laytpl'], function(){
	  var table = layui.table;
	  var laydate = layui.laydate;
	  var $ = layui.jquery;
	  var laytpl = layui.laytpl;
	  
	  //时间范围
	  laydate.render({
	  	elem: '#time',
	  	type: 'datetime',
	  	range: '至',
	  	done: function(value){
	  	
	  	}
	  });
		  
	  //定义属性
	  table.render({
	    elem: '#stuTable'//关联表格
	    ,url: '<%=path%>/biz/Treat_getByPager.action' //数据接口
	    ,page: true //开启分页
	    ,cols: [[ //表头
	       {type:'numbers'}
	      ,{type:'checkbox', field: "left"}
	      ,{field: 'treatId', title: '诊疗编号', align:'center', sort:true}
	      ,{field: 'regId', title: '挂号编号', width: 120, align:'center', sort: true}
	      ,{field: 'stuName', title: '姓名', align:'center',  sort:true, templet: function(data){
	      	    var color = "#D2691E";
	      		return '<span style="font-weight: bold ;color: '+color+';">'+data.stuName+'</span>';
	      }}
	      ,{field: 'stuSex', title: '性别', width: 80, align:'center', sort: true}
	      ,{field: 'stuAge', title: '年龄', width: 80, align:'center', sort: true}
	      ,{field: 'userName', title: '医师', width: 100, align:'center', sort: true, templet: function(data){
	      	    var color = "#6959CD";
	      		return '<span style="font-weight: bold ;color: '+color+';">'+data.userName+'</span>';
	      }}
		  ,{field: 'treatMethod', title: '诊疗方法', align:'center', sort: true}
		  ,{field: 'treatResult', title: '诊疗结果', align:'center', sort: true, templet: function(data){
		  		var color = "#CD2626";
	      		return '<span style="font-weight: bold ;color: '+color+';">'+data.treatResult+'</span>';
		  }}
	      ,{field: 'treatDate', title: '诊疗时间', align:'center', templet: function(d){
	      		//格式化时间
	      		var date = new Date(d.treatDate.time).toLocaleDateString();
	      		return '<span style="font-weight: bolder ;color: #8B0A50;">'+date+'</span>';
	      }, sort: true}
	      ,{field: 'treatCount', title: '处方单数', width: 100, align:'center', sort: true}
	      ,{field: 'state', title: '状态', width: 100, align:'center', templet : function(d){
		      	//函数转义 自定义列模板
		      	var status;
		      	var color;
		      	switch(d.state){
		      	case 0:
		      		color = '#FF69B4';
		      		status = '等待处方';break;
		      	case 1:
		      		color = '#0066CC';
		      		status = '吃药中';break;
		      	case 2:
		      		color = '#080808';
		      		status = '治疗失败';break;
		      	case 3:
		      		color = '#698B22';
		      		status = '治疗完成';break;
		      	case 4:
		      		color = '#CD0000';
		      		status = '死亡';break;
		      	}
		      	return '<span style="font-weight: bolder ;color: '+color+';">'+status+'</span>';
	      }, sort: true}
	      ,{field: 'operate', title: '操作', width: 220, field: "right", align:'center', toolbar: '#barDemo'}//这里的toolbar值是模板元素的id选择器
	    ]]
	    ,id: 'testReload'
	    ,height: 'full-80' //分页块与表格之间的距离
	    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
	    
	  });
	  
	  //表格数据重载
	  var $ = layui.$, active = {
	    reload: function(){
	      var demoReload = $('#demoReload');
	      //执行重载
	      table.reload('testReload', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	stuDesc: demoReload.val(),
	        	timeSection: trimTime($('#time').val())
	        }
	      });
	    }
	  };
	  $('.demoTable .layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
	  
	  //监听工具条
	  table.on('tool(tableDemo)', function(obj){
	    //获取data属性
	    var data = obj.data;
	    if(obj.event === 'del'){
	      message("待完善");
	      return;
	      layer.confirm('真的删除行么', function(index){
	      	$.ajax({
	      		url: '<%=path%>/biz/Treat_delete.action',
	      		type: 'GET',
	      		data: {"regId":data.treatId},
	      		dataType: 'json',
	      		success: function(data){
	      			var json = eval("("+data+")");
	      			if(json.isSucceed){
	      				message("删除成功");
	      				//删除页面记录
	      				obj.del();
	      				
	      			}else{
	      				message("删除失败~不解释");
	      			}
	      		},
	      		error: function(data){
	      			layer.msg("请求失败");
	      		}
	      	});
	      	//关闭弹窗
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
	      message("待完善");
	      return;
	       //获取挂号编号
	       var regId = data.regId;
	       //iframe窗
			layer.open({
		      type: 2,
		      title: '编辑学生挂号信息',
		      btnAlign: 'c',
		      shadeClose: true,
		      shade: false,
		      maxmin: true, //开启最大化最小化按钮
		      area: ['893px', '600px'],
		      content: '<%=path%>/biz/Student_openUpdate.action?regId='+regId
			});
	    } else if(obj.event === 'recipeAdd'){
	    	var treatId = data.treatId;
	    	//如果死亡
	    	if(data.state == 4){
	    		message("节哀顺变~");
	    		return
	    	}else if(data.state == 3){
	    		message("已完成治疗~")
	    		return
	    	}
	    	layer.open({
	    		type: 2,
	    		title: '开处方',
	    		shadeClose: true,
	    		shade: false,
	    		maxmin: true,
			    area: ['85%', '96%'],
			    content: '<%=path%>/biz/Recipe_openAdd.action?treat.treatId='+treatId
	    	});	
	    }
	  });
	  
	});
	
  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
          layer.closeAll();
        }
      });
  }


//为时间段加点杂碎并返回，防止被同化
function trimTime(strDate) { 
    if(null==strDate || ""==strDate){  
        return "";  
    }
    return "+"+strDate;
};


  </script>


<script type="text/html" id="barDemo">
	<sec:authorize ifAnyGranted="treatConsult">
  	<a class="layui-btn layui-btn-xs" lay-event="edit">详情</a>
	</sec:authorize>
	<sec:authorize ifAnyGranted="treatUpdate">
  	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	</sec:authorize>
	<sec:authorize ifAnyGranted="treatDelete">
  	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</sec:authorize>
	<sec:authorize ifAnyGranted="recipeAdd">
		<a id="treat" class="layui-btn layui-btn-xs"  lay-event="recipeAdd">开处方</a>
	</sec:authorize>
</script>


</html>
